#pragma once

#include <iostream>

using namespace std;

/**
 * @brief 定义抽象类
 *
 */
class Subject
{
public:
    virtual ~Subject() = default;

public:
    virtual void doSomething() = 0;
};

/**
 * @brief 实现类
 *
 */
class RealSubject : public Subject
{
public:
    RealSubject()           = default;
    ~RealSubject() override = default;

public:
    void doSomething() override
    {
        std::cout << "RealSubject::doSomething" << std::endl;
    }
};

/**
 * @brief 定义代理
 *
 */
class Proxy : public Subject
{
public:
    explicit Proxy(RealSubject *real_subject) : m_realSubject(real_subject), m_loginStatus(false)
    {
    }
    ~Proxy()
    {
        if (m_realSubject)
            delete m_realSubject;
    }

public:
    void login()
    {
        std::cout << "login success." << std::endl;
        m_loginStatus = true;
    }

    void logout()
    {
        std::cout << "logout success." << std::endl;
        m_loginStatus = false;
    }

    void doSomething() override
    {
        if (!m_loginStatus) {
            std::cout << "You not login." << std::endl;
            return;
        }
        m_realSubject->doSomething();
    }

private:
    RealSubject *m_realSubject;
    bool         m_loginStatus;
};
